<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <!--<a-col :span="24">
            <a-form-model-item label="发生时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
              <j-date placeholder="请选择发生时间"  v-model="model.createTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="ip地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ip">
              <a-input v-model="model.ip" placeholder="请输入ip地址"  ></a-input>
            </a-form-model-item>
          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="参数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="params">
              <a-textarea v-model="model.params" placeholder="请输入参数"  ></a-textarea>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="方法名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="methodName">
              <a-input v-model="model.methodName" placeholder="请输入方法名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="异常类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exceptionType">
              <a-input v-model="model.exceptionType" placeholder="请输入异常类型"  ></a-input>
            </a-form-model-item>
          </a-col>
         <!-- <a-col :span="24">
            <a-form-model-item label="是否查看" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isView">
              <j-dict-select-tag type="radio" v-model="model.isView" dictCode="yn" placeholder="请选择是否查看" />
            </a-form-model-item>
          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="异常消息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exceptionMessage">
              <!--<a-textarea v-model="model.exceptionMessage" rows="4" placeholder="请输入异常消息" />-->
              <j-code-editor ref="codeEditor"
                             language="json"
                             placeholder="请输入参数json"
                             :lineNumbers="true"
                             :fullScreen="true"
                             style="min-height: 100px"/>

            </a-form-model-item>
          </a-col>
         <!-- <a-col :span="24">
            <a-form-model-item label="1:系统异常,2:业务异常" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="logType">
              <j-dict-select-tag type="radio" v-model="model.logType" dictCode="errorLogType" placeholder="请选择1:系统异常,2:业务异常" />
            </a-form-model-item>
          </a-col>-->
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'SysErrorLogForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 2 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 22 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/sysErrorLog/add",
          edit: "/sysErrorLog/edit",
          queryById: "/sysErrorLog/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$refs.codeEditor.coder.setValue(this.model.exceptionMessage);
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>